﻿package mortal.game.net.command.redPacket
{
    import Framework.MQ.*;
    import Message.Command.*;
    import Message.Game.*;
    import Message.Public.*;
    import extend.language.*;
    import mortal.game.cache.*;
    import mortal.game.events.*;
    import mortal.game.mvc.*;
    import mortal.game.net.broadCast.*;
    import mortal.game.view.chat.chatPrivate.*;
    import mortal.game.view.guild.redPack.*;
    import mortal.mvc.core.*;

    public class RedPacketCommand extends BroadCastCall
    {

        public function RedPacketCommand(param1:Object)
        {
            super(param1);
            return;
        }// end function

        override public function call(param1:MessageBlock) : void
        {
            var _loc_2:SRedEnvelopeInfo = null;
            var _loc_3:SRobOutRedEnvelope = null;
            switch(param1.messageHead.command)
            {
                case EPublicCommand._ECmdPublicRedEnvelope:
                {
                    NetDispatcher.dispatchCmd(ServerCommand.RedPacketCanGive, null);
                    break;
                }
                case EPublicCommand._ECmdPublicRedEnvelopeRobOut:
                {
                    if (ChatManager.guildWindow && ChatManager.guildWindow.topTipData is SRedEnvelopeInfo)
                    {
                        _loc_3 = param1.messageBase as SRobOutRedEnvelope;
                        if ((ChatManager.guildWindow.topTipData as SRedEnvelopeInfo).redId == _loc_3.redId)
                        {
                            ChatManager.guildWindow.cancelTopTipHtmlText();
                        }
                        if (Cache.instance.redPackCache.guildRedEnvelopeInfo && Cache.instance.redPackCache.guildRedEnvelopeInfo.redId == _loc_3.redId)
                        {
                            RedPackGuildIcon.instance.stopEffect();
                        }
                        else if (Cache.instance.redPackCache.selfRedEnvelopeInfo && Cache.instance.redPackCache.selfRedEnvelopeInfo.redId == _loc_3.redId)
                        {
                            RedPackSelfIcon.instance.stopEffect();
                        }
                    }
                    break;
                }
                case EPublicCommand._ECmdPublicRedEnvelopeUsed:
                {
                    _loc_2 = param1.messageBase as SRedEnvelopeInfo;
                    if (_loc_2)
                    {
                        if (_loc_2.type == 0)
                        {
                            Cache.instance.redPackCache.guildRedEnvelopeInfo = _loc_2;
                            NetDispatcher.dispatchCmd(ServerCommand.RedPacketHasGiven, _loc_2);
                        }
                        else if (_loc_2.type == 2)
                        {
                            if (_loc_2.boss == null)
                            {
                                _loc_2.boss = new SMiniPlayer();
                            }
                            _loc_2.boss.name = Language.getString(35635);
                            Cache.instance.redPackCache.activeEnvelopeInfo = _loc_2;
                            GameController.chat.addGuildRedPackMsg(_loc_2);
                        }
                        else
                        {
                            Cache.instance.redPackCache.selfRedEnvelopeInfo = _loc_2;
                            NetDispatcher.dispatchCmd(ServerCommand.RedPacketHasGiven, _loc_2);
                        }
                    }
                    break;
                }
                case EPublicCommand._ECmdPublicRedEnvelopeOpen:
                {
                    _loc_2 = param1.messageBase as SRedEnvelopeInfo;
                    if (_loc_2)
                    {
                        if (_loc_2.type == 2)
                        {
                            if (_loc_2.boss == null)
                            {
                                _loc_2.boss = new SMiniPlayer();
                            }
                            _loc_2.boss.name = Language.getString(35635);
                            Cache.instance.redPackCache.activeEnvelopeInfo = _loc_2;
                            Dispatcher.dispatchEvent(new DataEvent(EventName.RedPackActiveOpen));
                        }
                        GameController.chat.addGuildRedPackMsg(_loc_2);
                    }
                    break;
                }
                default:
                {
                    break;
                }
            }
            return;
        }// end function

    }
}
